package com.store.app.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.store.app.R;
import com.store.app.bean.HPTDetailsBean;

import java.util.List;

public class HPTDetialsAdapter extends BaseAdapter {
    private List<HPTDetailsBean> hpyDetailsBeans;
    private Context context;


    public HPTDetialsAdapter(List<HPTDetailsBean> hpyDetailsBeans, Context context) {
        this.hpyDetailsBeans = hpyDetailsBeans;
        this.context = context;
    }

    @Override
    public int getCount() {
        return hpyDetailsBeans.size();
    }

    @Override
    public Object getItem(int position) {
        return hpyDetailsBeans.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        HPTDetailsBean hptDetailsBean = hpyDetailsBeans.get(position);
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_order_hpt_details, null);
            viewHolder.order_title = (TextView) convertView.findViewById(R.id.order_title);
            viewHolder.order_title2 = (TextView) convertView.findViewById(R.id.order_title2);
            viewHolder.order_id = (TextView) convertView.findViewById(R.id.order_id);
            viewHolder.order_date = (TextView) convertView.findViewById(R.id.order_date);
            viewHolder.order_count = (TextView) convertView.findViewById(R.id.order_count);
            viewHolder.order_message = (TextView) convertView.findViewById(R.id.order_message);
            viewHolder.order_state = (TextView) convertView.findViewById(R.id.order_state);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.order_title.setText(hptDetailsBean.getContact_person());
        viewHolder.order_title2.setText(hptDetailsBean.getContact_tel());
        viewHolder.order_id.setText("订单编号: "+hptDetailsBean.getOrder_no());
        viewHolder.order_date.setText("创建时间: "+hptDetailsBean.getOrder_date());
        viewHolder.order_count.setText("商品数量: "+hptDetailsBean.getQty());
        if(TextUtils.isEmpty(hptDetailsBean.getDesc2())){
            viewHolder.order_message.setVisibility(View.GONE);
        }else{
            viewHolder.order_message.setVisibility(View.VISIBLE);
            viewHolder.order_message.setText("订单留言: "+hptDetailsBean.getDesc2());
        }

        String status = hptDetailsBean.getStatus();

        if ("paid".equals(status)) {
            status = "已支付";
        } else if ("delivered".equals(status)) {
            status = "已发货";
        } else if ("received".equals(status)) {
            status = "已收货";
        } else if ("cancelled".equals(status)) {
            status = "订单取消";
        } else if("arrived".equals(status)){
            status = "已到货";
        }else {
            status = "未知";
        }
        viewHolder.order_state.setText(status);
        Log.v("zyl" ,"order_titleorder_titleorder_titleorder_title:"+hptDetailsBean.getContact_person());

        return convertView;
    }


    class ViewHolder {
        private TextView order_title;
        private TextView order_title2;
        private TextView order_id;
        private TextView order_date;
        private TextView order_count;
        private TextView order_message;
        private TextView order_state;
    }
}
